/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hcmus.fit.master.sevensea.sprite.ship;

import hcmus.fit.master.sevensea.background.Sea;
import hcmus.fit.master.sevensea.core.AbstractSprite;
import hcmus.fit.master.sevensea.core.Constant;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Point;

/**
 * 
 * @author hvp
 */
public class Explosion extends AbstractSprite {
    public static List<List<Bitmap>> Resource;

    // public static Player Sound;

    public Explosion(Sea seamap, int x, int y) {
        super(seamap, x, y);
        setRealPos(new Point(x * Constant.CELL_WIDTH - 7, y * Constant.CELL_HEIGHT
                - Constant.CELL_HEIGHT / 2));
        setFrames(Resource.get(0));
        setNbOfFrame(getFrames().size());
        setIndex(0);
    }

    public boolean update() {
        setIndex(getIndex() + 1);
        if (getIndex() >= getNbOfFrame()) {
            getSeaMap().items.remove(this);
            return false;
        }
        return true;
    }

    public static List<List<Bitmap>> GetResource(Bitmap resource, int maxX, int maxY, int numerator,
            int denominator) {
        List<List<Bitmap>> rs = new ArrayList<List<Bitmap>>();
        int w = resource.getWidth() / maxX;
        int h = resource.getHeight() / maxY;

        for (int i = 0; i < maxY; i++) {
            List<Bitmap> tmp = new ArrayList<Bitmap>();

            for (int j = 0; j < maxX; j++) {
                tmp.add(Bitmap.createBitmap(resource, j * w, i * h, w, h));
            }
            rs.add(tmp);
        }
        return rs;
    }
}
